import { dialog, Menu } from 'electron'
import type { MenuItemConstructorOptions } from 'electron'
//https://www.electronjs.org/docs/api/menu-item //查看角色
export const menutemplate: MenuItemConstructorOptions[] = [
  {
    label: ''
  },
  {
    label: 'Edit',
    submenu: [
      { label: 'Undo', accelerator: 'CmdOrCtrl+Z' },
      { label: 'Redo', accelerator: 'Shift+CmdOrCtrl+Z' },
      { type: 'separator' },
      { label: 'Cut', accelerator: 'CmdOrCtrl+X' },
      { label: 'Copy', accelerator: 'CmdOrCtrl+C' },
      { label: 'Paste', accelerator: 'CmdOrCtrl+V' },
      { label: 'Select All', accelerator: 'CmdOrCtrl+A' }
    ]
  },
  {
    label: '文件', // 一级标题
    submenu: [
      // 二级标题
      {
        label: '新建文件',
        accelerator: 'ctrl+n',
        submenu: [
          // 三级标题
          {
            label: 'HTML文件',
            click: () => {
              // + val.sender.getTitle()
              dialog.showMessageBox({
                title: '提示',
                message: '你点击了'
              })
            }
          },
          {
            label: 'JS文件'
          },
          {
            label: 'CSS文件'
          }
        ]
      },
      {
        label: '当前窗口切换至全屏模式',
        accelerator: 'CommandOrControl+A',
        role: 'togglefullscreen',
        click: () => {}
      },
      {
        label: '打开调试',
        role: 'toggleDevTools'
      },
      {
        label: '刷新',
        accelerator: 'CommandOrControl+r',
        role: 'reload'
        // click: () => {},
      }
    ]
  }
]
//主进程`ready`中调用
//设置应用菜单
const me = Menu.buildFromTemplate(menutemplate)
Menu.setApplicationMenu(me)
